program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  arrint = array of Integer;

var
  v, i, j, k, a, min, minv, minversh: Integer;
  matrix, graphmatrix: array of arrint;
  versh: arrint;
  flag: Boolean;

begin
  read(v);

  SetLength (versh, v);

  SetLength (matrix, v);
  SetLength (graphmatrix, v);
  for i:=0 to v-1 do
  begin
    SetLength (matrix[i], v);
    SetLength (graphmatrix[i], v);
    for j:=0 to v-1 do
    begin
      graphmatrix[i, j]:=0;
    end;
  end;

  for i:=0 to v-1 do
  begin
    for j:=0 to v-1 do
    begin
      read(matrix[i, j]);
    end;
  end;

  minv:=0;
  minversh:=0;
  for j:=1 to v-1 do
  begin
    versh[j-1]:= minv;
    min:=1000;
    a:=0;
    for i:=0 to j*(v-1) do
    begin
      flag:=True;
      if (i mod v = 0) and (i <> 0) then
      begin
        a:=a+1;
      end;
      for k:=0 to j-1 do
      begin
        if (i mod v = versh[k]) then
        begin
          flag:=False;
        end;
      end;
      if (matrix[versh[a], i mod v] < min) and (matrix[versh[a], i mod v] <> 0) and (flag = True) then
      begin
        min:=matrix[versh[a], i mod v];
        minv:= i mod v;
        minversh:=versh[a];
      end;
    end;
    graphmatrix[minversh, minv]:=min;
    graphmatrix[minv, minversh]:=min;
  end;

  for i:=0 to v-1 do
  begin
    for j:=0 to v-1 do
    begin
      write(graphmatrix[i, j], ' ');
    end;
    Writeln;
  end;
  readln;
  readln;
end.
